/*
 * @Author: Mcc
 * @Date: 2024-08-09 11:16:49
 * @LastEditors: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @LastEditTime: 2024-09-19 10:39:30
 * @FilePath: \ft-apply-admin\src\store\common\comStore.ts
 * @Description: 
 * 
 * Copyright (c) 2024 by Mcc, All Rights Reserved. 
 */

import { processList } from "@/views/ApplicationDetails/application-detail-data"
import { defineStore } from 'pinia';
import { selectResumesById } from "@/api/application-details/index.ts";
import { getCount } from '@/api/applay/side/side'
import { message } from "ant-design-vue";
export const comStores = defineStore('comStore', {
  state: () => ({
    //用户的信息
    userInFor: {
    },
    currentProcess: {

    },
    currentResume: {

    },
    noticeNumber: -1,
    menuCountList: {}
  }),
  getters: {
    // 可选，定义 getter 用于孙子组件读取所需状态
    getUserInFor(state) {//更新用户的信息
      return state.userInFor;
    },
  },
  actions: {
    setUserInFor(data) {//更新用户的信息
      this.userInFor = data;
    },
    async getResumeInfo(resumeId) {
      const data: any = await selectResumesById({ resumeId: +resumeId });
      if (data && data.code === '10000') {
        const resume = { ...data.data, resumeId: +resumeId }
        this.currentResume = resume;
        this.currentProcess = processList.find(el => el.key == resume.processSort) as any;
        if (!this.currentProcess) {
          this.currentProcess = { key: resume.processSort, label: resume.processDetail }
        }
      } else {
        message.error("获取简历信息失败");
        this.currentResume = {};
        this.currentProcess = {}
      }
    },
    // 设置左侧菜单数据
    async getMenuCountList() {
      const res = await getCount({
        "userId": this.userInFor.userId,
        "userName": this.userInFor.userName,
      })
      this.menuCountList = res
    }
  },

  persist: true,
});
